<?php
	session_start( );
	require_once('connections/mysqlDB.php');
	$dbConn = new mysqli(HOST,USER,PWD,DB);
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><!--DVID=00001DE9-->
<HTML>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<LINK href="frmm.css" rel="stylesheet" type="text/css">
<title>慕主先鋒教會</title>

<script language="javascript">
	function isDigit(c) {
		return ((c >= "0") && (c <= "9"))
	}

	function isInteger(s) {
		var i;
		for (i = 0; i < s.length; i++) {
			var c = s.charAt(i);
			if (!isDigit(c)) {
				return false;
			}
		}
		return true;
	}

	function validateRoomNumber() {
		var o = document.share_room_form.room_number;
		if (o.value == "") {
			alert("Please enter room number to share");
			return false;
		}
		if (!isInteger(o.value)) {
			alert(o.value + " is not a valid room number");
			return false;
		}
		return true;
	}
</script>

</head>
<?php
$regid=  $_SESSION['regid'];
$email =  $_SESSION['email'];
$fullname= $_SESSION['fullname']; 
?>
<body link=#3060c0 vlink=#3060c0>

<div id="container"> 
  <h1><img src="frmmtitlePic.jpg" width="785" height="75"></h1>


  <div id="thin-col">
登入名(Login as)<br><li><a href="con_registrant.php"><?php echo $_SESSION['fullname']; ?></a>
<p>

<a href=logout.php>登出(Logout)</a>
<hr color=#c0c0c0 size = 1>

特會報名<br>(Registration for)</b><li><?php echo $_SESSION['conferenceID']; ?>
<p>

    <!-- * Be sure to validate your HTML and CSS before including these buttons 
    		 * HTML Validator: http://webdesign.about.com/od/validators/l/bl_validation.htm#htmlvalidator
         * CSS Validator: http://webdesign.about.com/od/validators/l/bl_validation.htm#cssvalidator
    -->

<a href="con_newreg.php"><font size=-1>替別人報名<br>(New Registration)</font></a><br><br>
<a href="con_shareroom.php"><font size=-1>我可以分享床位 Share My Room<br></font></a><br>
<a href="con_findroom.php"><font size=-1>床位 Find A Room<br></font></a><br>
<a href="con_sharecar.php"><font size=-1>我可以分享車位 Car Share<br></font></a><br>
<p>

</div>

<div id="thick-col">

<?php
	$result = mysqli_query($dbConn, "select regid from registrant where email = '$email'");
	$row = mysqli_fetch_array($result);
	$ownerId = $row['regid'];
	$result = mysqli_query($dbConn, "select NUMBER, (select NAME from HOTEL where ID=HOTEL) AS HOTEL, AVAILABILITY, CHECKIN_DATE, CHECKOUT_DATE
		from SHARE_ROOM where OWNER = '$ownerId'");
	$hasData = FALSE;
	if ($result) {
		while ($row = mysqli_fetch_array($result)) {
			if (!$hasData) {
				echo "Your already shared room(s):<br><br>";
				echo "<table border=\"1\">";
				echo "<tr><td>Hotel Name</td><td>Room Number</td><td>Available Beds</td><td>Checkin Date</td><td>Checkout Date</td></tr>";
				$hasData = TRUE;			
			}
			echo "<tr>";
			echo "<td>".$row['HOTEL']."</td>";
			echo "<td>".$row['NUMBER']."</td>";
			echo "<td>".$row['AVAILABILITY']."</td>";
			echo "<td>".$row['CHECKIN_DATE']."</td>";
			echo "<td>".$row['CHECKOUT_DATE']."</td>";
			echo "</tr>";
		}
		if ($hasData) {
			echo "</table><br><br>";
		}
	}
?>

<form name="share_room_form" method="post" action="con_shareroom_proc.php" onSubmit="return validateRoomNumber()">
	<label for="hotel">Hotel:</label>
	<select name="hotel" id="hotel">
		<?php
			$result = mysqli_query($dbConn, "SELECT ID,NAME FROM HOTEL");
			while ($row = mysqli_fetch_array($result)) {
				echo "<option value=\"".$row['ID']."\">".$row['NAME']."</option>";
			}
		?>
	</select>
	
	<label>Room Number:</label>
	<input name="room_number" type="text" size="12" maxlength="6">
	
	<label for="room_capacity">Room Capacity:</label>
	<select name="room_capacity" id="room_capacity">
		<option value="2">2</option>
		<option value="3">3</option>
		<option value="4" selected>4</option>
		<option value="5">5</option>
		<option value="6">6</option>
		<option value="7">7</option>
		<option value="8">8</option>
	</select>
	
	<br><br>
	
	<label for="checkin_date">Checkin Date:</label>
	<select name="checkin_date" id="checkin_date">
		<option value="07/02/2009" selected>July 2, 2009</option>
		<option value="07/03/2009">July 3, 2009</option>
		<option value="07/04/2009">July 4, 2009</option>
		<option value="07/05/2009">July 5, 2009</option>
	</select>
	
	<label for="checkout_date">Checkout Date:</label>
	<select name="checkout_date" id="checkout_date">
		<option value="07/03/2009">July 3, 2009</option>
		<option value="07/04/2009">July 4, 2009</option>
		<option value="07/05/2009">July 5, 2009</option>
		<option value="07/06/2009" selected>July 6, 2009</option>
	</select>

	<p align="center">
		<input type="submit" name="Share My Room" value="Share My Room">
	</p>

</form>

</div> <!-- end of green box ->

</div> <!-- end of container ->

</body>
</html>
